﻿using Microsoft.VisualBasic.Logging;
using Sl.Duplex;
using Sl.Support.McuBytes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChholConfig {
	internal class ToHexDp : IDuplex {
		public override string Name => "输出到显示";

		public override bool IsRunning => is_running;
		public bool is_running = true;

		private StringBuilder mainSB = new StringBuilder(1024);
		public string getAllString() {
			string rev = mainSB.ToString();
			mainSB.Clear();
			return rev;
		}
		public ToHexDp() {
		}

		public override void closePort() {
			is_running = false;
		}

		public override string config(string str) {
			return string.Empty;
		}

		public override void openPort() {
			is_running = true;
		}

		public override int Read(byte[] buffer, int offset, int count) {
			return 0;
		}

		public override int ReadByte() {
			return -1;
		}

		public override void Write(byte[] buffer, int offset, int count) {
			for (int i = offset; i < offset + count; i++) {
				mainSB.Append(buffer[i].toHexStr());
				mainSB.Append(' ');
			}
		}
		public override void WriteByte(byte value) {
			mainSB.Append(value.toHexStr());
			mainSB.Append(' ');
		}
	}
}
